package com.firemoss.magicbus.messaging.fillter
{
	import mx.rpc.events.ResultEvent;

	public class ResultFilterChain extends AbstractFilterChain
	{
		public function ResultFilterChain( filters : Array = null )
		{
			super( filters );
		}

		override public function execute( ...rest ) : *
		{
			var event : ResultEvent = rest[ 0 ]
			var result : Object = rest.length == 0 ? event.result : rest[ 1 ]
			
			if ( result == null && event.result != null )
			{
				result = event.result
			} 
			
			for each ( var filter : ResultFilter in filterList )
			{
				result = filter.result( result, event )
			}
			
			return result
		}
		
	}
}